package com.bangdream.michelia.view.activity.exam;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.bangdream.michelia.R;
import com.bangdream.michelia.presenter.base.BasePresenter;
import com.bangdream.michelia.tool.GridSpacingItemDecoration;
import com.bangdream.michelia.utils.PublicUtil;
import com.bangdream.michelia.view.activity.base.SwipeBackActivity;
import com.bangdream.michelia.view.adapter.AnswerCardAdapter;
import com.bangdream.michelia.view.adapter.ExamResultAdapter;

/**
 * @date on 2018/8/19 2:56
 * @email 909732184@qq.com
 * 答题卡
 */
public class AnswerCardActivity extends SwipeBackActivity {
    private int index;
    private RecyclerView recyclerView;
    private GridLayoutManager gridLayoutManager;
    private AnswerCardAdapter adapter;
    @Override
    public int getLayout() {
        return R.layout.activity_answer_card;
    }

    @Override
    public void findId() {
        recyclerView = findViewById(R.id.recyclerView);
    }

    @Override
    public void setListener() {
        adapter.setOnViewItemClickListener(new AnswerCardAdapter.OnViewItemClickListener() {
            @Override
            public void onCurriculumItemClick(int position) {
                Intent intent = getIntent();
                intent.putExtra("index",position);
                setResult(Activity.RESULT_OK,intent);
                finish();
            }
        });
    }

    @Override
    public void logic() {
        if(getIntent().getExtras()!=null){
            index = getIntent().getExtras().getInt("index");
        }
        initTitleBar(" ","答题卡","",this);

        //网格布局分为两列
        gridLayoutManager = new GridLayoutManager(this,7);
        adapter = new AnswerCardAdapter(this);
        adapter.setCurrentIndex(index);
        recyclerView.setLayoutManager(gridLayoutManager);

        //设置每个item间距
        recyclerView.addItemDecoration(new GridSpacingItemDecoration(7, PublicUtil.dip2px(this,10),false));
        recyclerView.setAdapter(adapter);
    }

    @Override
    public BasePresenter createPresenter() {
        return null;
    }
}
